package com.situ.temp;

import java.util.Scanner;

public class StudentManager {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入学生数量：");
        int count = scanner.nextInt();
        Student[] array = new Student[count];
        for (int i = 0; i < array.length; i++) {
            //每遍历一次，构造一个学生对象，放到数组里面
            System.out.println("请输入id：");
            int id = scanner.nextInt();
            System.out.println("请输入name：");
            String name = scanner.next();
            System.out.println("请输入age：");
            int age = scanner.nextInt();
            System.out.println("请输入className：");
            String className = scanner.next();

            Student student = new Student(id, name, age, className);
            array[i] = student;
        }

        //遍历打印所有数组信息
        for (int i = 0; i < array.length; i++) {
            //Student student = array[i];
            //System.out.println(student);
            System.out.println(array[i]);
        }

        //Unreachable statement
        while (true) {
            //按照条件搜索
            System.out.println("输入1按照id搜索：");
            System.out.println("输入2按照name搜索：");
            System.out.println("输入3按照age搜索：");
            System.out.println("输入4按照className搜索：");
            System.out.println("输入0退出搜索：");
            int type = scanner.nextInt();
            if (type == 0) {
                System.out.println("退出搜索");
                break;
            }

            switch (type) {
                case 1:
                    break;
                case 2://name
                    System.out.println("请输入要搜索的name：");
                    String name = scanner.next();
                    for (int i = 0; i < array.length; i++) {
                        Student student = array[i];
                        //String里面有一个方法equals()
                        //如果相等就返回true，否则返回false
                        if (student.getName().equals(name)) {
                            System.out.println(student);
                        }
                    }
                    break;
                case 3://age
                    System.out.println("请输入要搜索的age：");
                    int age = scanner.nextInt();
                    for (int i = 0; i < array.length; i++) {
                        Student student = array[i];
                        if (student.getAge() == age) {
                            System.out.println(student);
                        }
                    }
                    break;
                case 4:
                    break;
            }
        }


    }
}
